package cn.bby.query.base.model.req;

import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;

import java.io.Serializable;
import java.util.Collections;
import java.util.List;

/**
 * @author ben
 * @since 2025/4/12 02:29
 */
@Data
@NoArgsConstructor
@Accessors(chain = true)
public class QueryResponse<T> implements Serializable {
    private static final long serialVersionUID = -1038632677234098909L;
    /**
     * 总数
     */
    private Long total;
    /**
     * 数据
     */
    private List<T> dataSet;
    /**
     * 当前页码
     */
    private Integer page;
    /**
     * 每页数量
     */
    private Integer size;

    public QueryResponse(Long total, List<T> data, QueryRequest request) {
        this.total = total;
        this.page = request.getPage();
        this.size = request.getSize();
        this.dataSet = data;
    }

    public QueryResponse(QueryRequest request) {
        this.page = request.getPage();
        this.size = request.getSize();
        this.total = 0L;
        this.dataSet = Collections.emptyList();
    }
}
